<!-- 小组成员 -->

<template>
  <WebTable :list="one.emergencyMemberDto" idKey="memberUaaUserId" class="EmergencyGroup-GroupMember" noPage auto>
    <RowTitle label="人员名称" bind="memberUserName">
      <template #default="{ row, text }">
        <span>{{ text }}</span>
        <i v-if="row.isLeader === 1" class="el-icon-user-solid" />
      </template>
    </RowTitle>

    <RowText :label="`所属${CORE.MAP.ORGAN}`" bind="organizationName" :minWidth="100" />

    <RowText label="联系电话" bind="memberUserPhone" />

    <RowOperate v-bind="MAP.MEMBER_PROPS" :onPass="toPass" :onRej="toRej" :onDel="toDel" />
  </WebTable>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'GroupMember',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixWeb()],

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    /**
     * 通过
     */
    toPass(row) {
      this.one.leaderId = row.memberUaaUserId

      this.one.emergencyMemberDto.forEach((obj) => {
        obj.isLeader = row.memberUaaUserId === obj.memberUaaUserId ? 1 : 2
      })
    },

    /**
     * 拒绝
     */
    toRej(row) {
      this.one.leaderId = ''

      const obj = this.one.emergencyMemberDto.find((item) => item.id === row.id)
      obj.isLeader = 2
    },

    /**
     * 删除
     */
    toDel(row) {
      if (row.memberUaaUserId === this.one.leaderId) this.one.leaderId = ''

      const index = this.one.emergencyMemberDto.findIndex((item) => item.id === row.id)
      this.one.emergencyMemberDto.splice(index, 1)
    },
  },
}
</script>

<style lang="scss">
@import './index.scss';
</style>
